//
//  Cloud_tableViewCellThree.m
//  EggSteward
//
//  Created by 王道林 on 16/9/1.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "Cloud_tableViewCellThree.h"
#import "BaseView.h"
#import "Masonry.h"

@interface Cloud_tableViewCellThree ()<UITextFieldDelegate>
@property (nonatomic, strong) BaseView *View;
@property (nonatomic, strong) UIView *viewLineO;
@property (nonatomic, strong) UIView *viewLineT;
@property (nonatomic, strong) UIView *viewLineS;
@end

@implementation Cloud_tableViewCellThree

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
        [self notification];
    }
    return self;
}
- (void)notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"day" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dayTime:) name:@"day" object:nil];
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    BOOL is = [userDefault boolForKey:@"night"];
    if (is == NO) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"day" object:nil userInfo:nil];
    }
}
- (void)dayTime:(NSNotification *)sender
{
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
}

- (void)createSubview
{
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    // 背景view
    _View = [[BaseView alloc] init];
    _View.backgroundColor = [UIColor whiteColor];
    _View.layer.masksToBounds = YES;
    _View.layer.cornerRadius = 10;
    [self.contentView addSubview:_View];
    // lable
    _lableGroup = [[BaseLabel alloc] init];
    _lableGroup.text = @"群体量";
    [_View addSubview:_lableGroup];
    _lableTakeTime = [[BaseLabel alloc] init];
    _lableTakeTime.text = @"采样时间";
    [_View addSubview:_lableTakeTime];
    _lableSendTime = [[BaseLabel alloc] init];
    _lableSendTime.text = @"送检时间";
    [_View addSubview:_lableSendTime];
    _lableSample = [[BaseLabel alloc] init];
    _lableSample.text = @"样品";
    [_View addSubview:_lableSample];
    // textfield
    _textFieldGroup = [[BaseTextField alloc] init];
    _textFieldGroup.delegate = self;
    _textFieldGroup.placeholder = @"检测群体量";
    [_View addSubview:_textFieldGroup];
    _textFieldTakeTime = [[BaseTextField alloc] init];
    _textFieldTakeTime.delegate = self;
    _textFieldTakeTime.placeholder = @"采样时间";
    [_View addSubview:_textFieldTakeTime];
    _textFieldSendTime = [[BaseTextField alloc] init];
    _textFieldSendTime.delegate = self;
    _textFieldSendTime.placeholder = @"送检时间";
    [_View addSubview:_textFieldSendTime];
    _textFieldSample = [[BaseTextField alloc] init];
    _textFieldSample.delegate = self;
    _textFieldSample.placeholder = @"样品";
    [_View addSubview:_textFieldSample];
    
    // 横线
    _viewLineO = [[UIView alloc] init];
    _viewLineO.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineO];
    _viewLineT = [[UIView alloc] init];
    _viewLineT.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineT];
    _viewLineS = [[UIView alloc] init];
    _viewLineS.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineS];
    
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    [_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).mas_offset(20);
        make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-20);
        make.top.mas_equalTo(self.contentView.mas_top);
        make.bottom.mas_equalTo(self.contentView.mas_bottom);
    }];
    // lable 的约束
    [_lableGroup mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_View.mas_top);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.25);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    [_lableTakeTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_lableGroup.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.25);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    [_lableSendTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_lableTakeTime.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.25);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    [_lableSample mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_lableSendTime.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.25);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    // textfield 的约束
    [_textFieldGroup mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lableGroup.mas_right).mas_offset(10);
        make.top.mas_equalTo(_View.mas_top);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableGroup.mas_height);
    }];
    [_textFieldTakeTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lableTakeTime.mas_right).mas_offset(10);
        make.top.mas_equalTo(_textFieldGroup.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableGroup.mas_height);
    }];
    [_textFieldSendTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lableSendTime.mas_right).mas_offset(10);
        make.top.mas_equalTo(_textFieldTakeTime.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableGroup.mas_height);
    }];
    [_textFieldSample mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lableSample.mas_right).mas_offset(10);
        make.top.mas_equalTo(_textFieldSendTime.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableGroup.mas_height);
    }];
    
    // 横条
    [_viewLineO mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_textFieldGroup.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
    // 横条
    [_viewLineT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_textFieldTakeTime.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
    // 横条
    [_viewLineS mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_textFieldSendTime.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];

}
// 回收键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}




@end
